
********************************
** Loading and Preparing Data **
********************************


* Loading the dataset *
use "../civic_honesty_public.dta", clear




snapshot erase _all
snapshot save

snapshot restore 1
recode response(100=1)

***********************************************
*** By country, country-ordered regressions ***
***********************************************
gen money=1 if cond==1
recode money (.=0)
gen bigmoney=1 if cond==2
recode bigmoney (.=0)
gen nokey=1 if cond==3
recode nokey (.=0)

* Sweden
reg response public postal i.cond busy if country==34, 
gen country_public_coef = _b[public] if country==34,  
gen country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==34,
gen country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==34,

* Switzerland
reg response public postal i.cond busy if country==35, 
replace country_public_coef = _b[public] if country==35 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==35 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==35 & country_public_uci==.,

* UK 
reg response public postal i.cond busy if country==39, 
replace country_public_coef = _b[public] if country==39 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==39 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==39 & country_public_uci==.,

* Kenya
reg response public postal i.cond busy if country==19, 
replace country_public_coef = _b[public] if country==19 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==19 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==19 & country_public_uci==.,

* Australia 
reg response public postal i.cond busy if country==2, 
replace country_public_coef = _b[public] if country==2 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==2 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==2 & country_public_uci==.,

* Indonesia
reg response public postal i.cond busy if country==15, 
replace country_public_coef = _b[public] if country==15 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==15 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==15 & country_public_uci==.,

* New Zealand
reg response public postal i.cond busy if country==24, 
replace country_public_coef = _b[public] if country==24 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==24 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==24 & country_public_uci==.,

* Mexico 
reg response public postal i.cond busy if country==21, 
replace country_public_coef = _b[public] if country==21 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==21 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==21 & country_public_uci==.,

* Ghana 
reg response public postal i.cond busy if country==12, 
replace country_public_coef = _b[public] if country==12 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==12 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==12 & country_public_uci==.,

* Thailand
reg response public postal i.cond busy if country==36, 
replace country_public_coef = _b[public] if country==36 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==36 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==36 & country_public_uci==.,

* Israel
reg response public postal i.cond busy if country==16, 
replace country_public_coef = _b[public] if country==16 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==16 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==16 & country_public_uci==.,

* Canada 
reg response public postal i.cond busy if country==4, 
replace country_public_coef = _b[public] if country==4 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==4 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==4 & country_public_uci==.,

* Germany 
reg response public postal i.cond busy if country==11, 
replace country_public_coef = _b[public] if country==11 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==11 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==11 & country_public_uci==.,

* Denmark 
reg response public postal i.cond busy if country==9, 
replace country_public_coef = _b[public] if country==9 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==9 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==9 & country_public_uci==.,

* USA  
reg response public postal i.cond busy if country==40,
replace country_public_coef = _b[public] if country==40 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==40 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==40 & country_public_uci==.,

* Norway  
reg response public postal i.cond busy if country==25, 
replace country_public_coef = _b[public] if country==25 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==25 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==25 & country_public_uci==.,

* India
reg response public postal i.cond busy if country==14,
replace country_public_coef = _b[public] if country==14 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==14 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==14 & country_public_uci==.,

* UAE
reg response public postal i.cond busy if country==38, 
replace country_public_coef = _b[public] if country==38 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==38 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==38 & country_public_uci==.,

* Brazil  
reg response public postal i.cond busy if country==3, 
replace country_public_coef = _b[public] if country==3 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==3 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==3 & country_public_uci==.,

* Greece
reg response public postal i.cond busy if country==13, 
replace country_public_coef = _b[public] if country==13 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==13 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==13 & country_public_uci==.,

* China 
reg response public postal i.cond busy if country==6, 
replace country_public_coef = _b[public] if country==6 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==6 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==6 & country_public_uci==.,

* Chile 
reg response public postal i.cond busy if country==5, 
replace country_public_coef = _b[public] if country==5 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==5 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==5 & country_public_uci==.,

* Portugal
reg response public postal i.cond busy if country==28,
replace country_public_coef = _b[public] if country==28 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==28 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==28 & country_public_uci==.,

* Poland
reg response public postal i.cond busy if country==27,
replace country_public_coef = _b[public] if country==27 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==27 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==27 & country_public_uci==.,

* Netherlands
reg response public postal i.cond busy if country==23, 
replace country_public_coef = _b[public] if country==23 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==23 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==23 & country_public_uci==.,

* Malaysia
reg response public postal i.cond busy if country==20, 
replace country_public_coef = _b[public] if country==20 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==20 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==20 & country_public_uci==.,

* Spain
reg response public postal i.cond busy if country==33, 
replace country_public_coef = _b[public] if country==33 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==33 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==33 & country_public_uci==.,

* France 
reg response public postal i.cond busy if country==10,
replace country_public_coef = _b[public] if country==10 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==10 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==10 & country_public_uci==.,

* Argentina
reg response public postal i.cond busy if country==1, 
replace country_public_coef = _b[public] if country==1 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==1 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==1 & country_public_uci==.,

* Turkey 
reg response public postal i.cond busy if country==37, 
replace country_public_coef = _b[public] if country==37 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==37 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==37 & country_public_uci==.,

* Morocco
reg response public postal i.cond busy if country==22, 
replace country_public_coef = _b[public] if country==22 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==22 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==22 & country_public_uci==.,

* Kazakhstan
reg response public postal i.cond busy if country==18, 
replace country_public_coef = _b[public] if country==18 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==18 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==18 & country_public_uci==.,

* Italy
reg response public postal i.cond busy if country==17,
replace country_public_coef = _b[public] if country==17 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==17 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==17 & country_public_uci==.,

* Croatia 
reg response public postal i.cond busy if country==7, 
replace country_public_coef = _b[public] if country==7 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==7 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==7 & country_public_uci==.,

* South Africa 
reg response public postal i.cond busy if country==32, 
replace country_public_coef = _b[public] if country==32 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==32 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==32 & country_public_uci==.,

* Romania
reg response public postal i.cond busy if country==29,
replace country_public_coef = _b[public] if country==29 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==29 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==29 & country_public_uci==.,

* Russia
reg response public postal i.cond busy if country==30, 
replace country_public_coef = _b[public] if country==30 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==30 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==30 & country_public_uci==.,

* Czech Republic 
reg response public postal i.cond busy if country==8, 
replace country_public_coef = _b[public] if country==8 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==8 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==8 & country_public_uci==.,

* Peru
reg response public postal i.cond busy if country==26, 
replace country_public_coef = _b[public] if country==26 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==26 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==26 & country_public_uci==.,

* Serbia
reg response public postal i.cond busy if country==31, 
replace country_public_coef = _b[public] if country==31 & country_public_coef==.
replace country_public_lci = _b[public] - invttail(e(df_r),0.025)*_se[public] if country==31 & country_public_lci==.,
replace country_public_uci = _b[public] + invttail(e(df_r),0.025)*_se[public] if country==31 & country_public_uci==.,


* Labels
label var country "Country ID number"
label var Country "Country name"
label var country_public_coef "The Public Sector coef. in each country"
label var country_public_lci "The Public Sector coef.'s 95% Lower CI in each country"
label var country_public_lci "The Public Sector coef.'s 95% upper CI in each country"


* One observation in each country
egen tag_country=tag(country)

* Dropping all observation but one in each country
keep if tag_country==1

* Removing unnecessary variables
drop id
drop city-nokey

* Sorting by the 'country_public_coef' variable (in descending order)
gsort -country_public_coef



** giving the countries numbers (so they would "fit" the rcap command)
gen num=_n
*gen c_number=41-num

* Renaming variables
rename country_public_coef coef
rename country_public_lci lci
rename country_public_uci hci

* Produce Whiskers graph ('rspike' instead of 'rcap')
twoway rspike lci hci num, ///
xlabel(1 "Sweden" 2 "Switzerland" 3 "United Kingdom" 4 "Australia" 5 "Indonesia" ///
	   6 "Kenya" 7 "New Zealand" 8 "Thailand" 9 "Mexico" 10 "Ghana" 11 "Israel" ///
	   12 "Canada" 13 "Germany" 14 "Denmark" 15 "United States" 16 "Norway" ///
	   17 "India" 18 "United Arab Emirates" 19 "Brazil" 20 "China" 21 "Greece" ///
	   22 "Malaysia" 23 "Netherlands" 24 "Poland" 25 "Chile" 26 "Portugal" 27 "Spain" ///
	   28 "Kazakhstan" 29 "Morocco" 30 "France" 31 "Peru" 32 "Turkey" 33 "Argentina" ///
	   34 "Croatia" 35 "Italy" 36 "South Africa" 37 "Czech Republic" 38 "Romania" ///
	   39 "Russia" 40 "Serbia", angle(90) labsize(vsmall)) ///
yline(0) ///
xtitle("") ///
ytitle("Public Sector coefficient") yscale(alt) || ///
scatter coef num, mcolor(black) msymbol(oh) ///
legend(off) scheme(s2mono) graphregion(fcolor(white)) 


graph save "public_whiskers_LPM_graph.gph", replace

